package com.huhao.demo;

import org.smartboot.socket.MessageProcessor;
import org.smartboot.socket.transport.AioQuickClient;
import org.smartboot.socket.transport.AioSession;
import org.smartboot.socket.transport.WriteBuffer;

import java.io.IOException;

public class StringClient {

    public static void main(String[] args) throws IOException, InterruptedException {
        MessageProcessor<String> processor = (session, msg) -> System.out.println("receive from server: " + msg);
        AioQuickClient client = new AioQuickClient("localhost", 8888, new StringProtocol(), processor);
        AioSession session = client.start();
        WriteBuffer writeBuffer = session.writeBuffer();
        byte[] data = "hello smart-socket".getBytes();
        writeBuffer.writeInt(data.length);
        writeBuffer.write(data);
        writeBuffer.flush();

        Thread.sleep(2000L);
        client.shutdown();
    }
}

